﻿using System;
using System.Collections.Generic;
using Terraria.Localization;

namespace Terraria.UI
{
	// Token: 0x02000113 RID: 275
	public class ItemTooltip
	{
		// Token: 0x170000D6 RID: 214
		// (get) Token: 0x06000C24 RID: 3108 RVA: 0x0000C6D8 File Offset: 0x0000A8D8
		public int Lines
		{
			get
			{
				this.ValidateTooltip();
				if (this._tooltipLines == null)
				{
					return 0;
				}
				return this._tooltipLines.Length;
			}
		}

		// Token: 0x06000C25 RID: 3109 RVA: 0x00006459 File Offset: 0x00004659
		private ItemTooltip()
		{
		}

		// Token: 0x06000C26 RID: 3110 RVA: 0x0000C6F2 File Offset: 0x0000A8F2
		private ItemTooltip(string key)
		{
			this._text = Language.GetText(key);
		}

		// Token: 0x06000C27 RID: 3111 RVA: 0x0000C706 File Offset: 0x0000A906
		public static ItemTooltip FromLanguageKey(string key)
		{
			if (!Language.Exists(key))
			{
				return ItemTooltip.None;
			}
			return new ItemTooltip(key);
		}

		// Token: 0x06000C28 RID: 3112 RVA: 0x0000C71C File Offset: 0x0000A91C
		public string GetLine(int line)
		{
			this.ValidateTooltip();
			return this._tooltipLines[line];
		}

		// Token: 0x06000C29 RID: 3113 RVA: 0x003F3638 File Offset: 0x003F1838
		private void ValidateTooltip()
		{
			if (this._lastCulture != Language.ActiveCulture)
			{
				this._lastCulture = Language.ActiveCulture;
				if (this._text == null)
				{
					this._tooltipLines = null;
					this._processedText = string.Empty;
					return;
				}
				string text = this._text.Value;
				foreach (TooltipProcessor tooltipProcessor in ItemTooltip._globalProcessors)
				{
					text = tooltipProcessor(text);
				}
				this._tooltipLines = text.Split(new char[]
				{
					'\n'
				});
				this._processedText = text;
			}
		}

		// Token: 0x06000C2A RID: 3114 RVA: 0x0000C72C File Offset: 0x0000A92C
		public static void AddGlobalProcessor(TooltipProcessor processor)
		{
			ItemTooltip._globalProcessors.Add(processor);
		}

		// Token: 0x06000C2B RID: 3115 RVA: 0x0000C739 File Offset: 0x0000A939
		public static void RemoveGlobalProcessor(TooltipProcessor processor)
		{
			ItemTooltip._globalProcessors.Remove(processor);
		}

		// Token: 0x06000C2C RID: 3116 RVA: 0x0000C747 File Offset: 0x0000A947
		public static void ClearGlobalProcessors()
		{
			ItemTooltip._globalProcessors.Clear();
		}

		// Token: 0x04000FFC RID: 4092
		public static readonly ItemTooltip None = new ItemTooltip();

		// Token: 0x04000FFD RID: 4093
		private static List<TooltipProcessor> _globalProcessors = new List<TooltipProcessor>();

		// Token: 0x04000FFE RID: 4094
		private string[] _tooltipLines;

		// Token: 0x04000FFF RID: 4095
		private GameCulture _lastCulture;

		// Token: 0x04001000 RID: 4096
		private LocalizedText _text;

		// Token: 0x04001001 RID: 4097
		private string _processedText;
	}
}
